﻿using System;
using System.Collections;
using System.Linq;
using System.Windows;
using System.Windows.Data;

namespace Luna.UI.Wpf
{
    public class DatasourceEmptyConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var L_datasource = value as IEnumerable;
            if (value != null)
            {
                if (parameter != null)
                {
                    return (L_datasource.OfType<object>().Count() == 0) == (bool)parameter;
                }
                else
                {
                    return L_datasource.OfType<object>().Count() == 0;
                }
            }

            return DependencyProperty.UnsetValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return DependencyProperty.UnsetValue;
        }
    }
}